<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Class HTMLHelper
 */
RExtImporter::cls("html.IMHelper");
class HTMLHelper {

    function videoPlay($link, $id = '', $width = 500, $height = 400, $previewpic = '') {
        // Use for RU only
        $id = $id.'player';
        $htmlReturn = '<div id="'.$id.'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div><script type="text/javascript">
		var '.$id.' = new SWFObject("'.SYS_CUR_TMPL_URL.'player/player.swf","","'.$width.'","'.$height.'","9","#FFFFFF");
		'.$id.'.addParam("allowfullscreen","true");
		'.$id.'.addParam("allownetworking","all");
		'.$id.'.addParam("allowscriptaccess","always");
		'.$id.'.addParam("flashvars","file='.$link.'&image='.$previewpic.'");
		'.$id.'.write("'.$id.'");
	</script>';
        return $htmlReturn;
    }
    
    function listDate() {
    	$dateArray = array();
    	for($i = 1; $i <= 31; $i++) {
    		if($i < 10){$i = '0'.$i;}
    		$dateArray[$i] = $i;
    	}
    	return $dateArray;
    }
    
    function listMonth() {
    	$month = array();
    	for($i = 1; $i <= 12; $i++) {
    		if($i < 10){$i = '0'.$i;}
    		$month[$i] = $i;
    	}
    	return $month;
    }
    
    function listYear() {
    	$year = array();
    	for($i = 1910; $i <= date('Y', time()); $i++) {
    		$year[$i] = $i;
    	}
    	return $year;
    }
    
    /**
     * Create a Yahoo contact icon.
     * @param $yahoo_id: string, a yahoo id
     * @return HTML object: A link to call Yahoo Client Messenger and create chat windows with input yahoo id
     */
    function createYahooIcon($yahoo_id, $createLink = false) {
    	static $yahooArray;
    	if(!isset($yahooArray[$yahoo_id])) {
	    	$status = IMHelper::checkYahooStatus($yahoo_id);
	    	if($status) {
	    		$imglink = SYS_CUR_TMPL_URL.'images/yh_online.png';
	    	} else {
	    		$imglink = SYS_CUR_TMPL_URL.'images/yh_offline.png';
	    	}
	    	if($createLink) {
	    		$yahooArray[$yahoo_id] = '<a href="ymsgr:sendIM?'.$yahoo_id.'" title="Send IM to '.$yahoo_id.'" ><img src="'.$imglink.'" title="Send IM to '.$yahoo_id.'" alt="Send IM to '.$yahoo_id.'" border="0" /></a>';
	    	} else {
	    		$yahooArray[$yahoo_id] = '<img src="'.$imglink.'" title="Login to chat Yahoo Messenger" alt="Login to chat Yahoo Messenger" border="0" />';
	    	}
    	}
    	return $yahooArray[$yahoo_id];
    }
    
    /**
     * Create skype icon, detect online and offline status
     * @param $skype_id
     * @return unknown_type
     */
    function createSkypeIcon($skype_id, $createLink = false) {
    	static $skypeArray;
    	if(!isset($skypeArray[$skype_id])) {
	    	$status = IMHelper::checkSkypeStatus($skype_id);
	    	if($status) {
	    		$imglink = SYS_CUR_TMPL_URL.'images/skype_online.png';
	    	} else {
	    		$imglink = SYS_CUR_TMPL_URL.'images/skype_offline.png';
	    	}
	    	if($createLink) {
	    		$skypeArray[$skype_id]= '<a href="skype:'.$skype_id.'?chat" title="Chat Skype with '.$skype_id.'" ><img src="'.$imglink.'" title="Chat Skype with '.$skype_id.'" alt="Chat Skype with '.$skype_id.'" border="0" /></a>';
	    	} else {
	    		$skypeArray[$skype_id] = '<img src="'.$imglink.'" title="Login to chat Yahoo Skype" alt="Login to chat Yahoo Skype" border="0" />';
	    	}
    	}
    	return $skypeArray[$skype_id];
    }
    
    
    function createCountryList() {
    	static $countrys;
    	if(!isset($countrys)) {
	    	RClassesImporter::cls("dbo.finders.CountryFinder" );
	    	$finder = new CountryFinder();
	    	
	    	$countryList = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$countrys = array();
	    	foreach ($countryList as $country) {
	    		$countrys[$country->country_id] = $country->country_name;
	    	}
    	}
    	return $countrys;
    }
    
    
    function createNationalityList() {
    	static $nationalitys;
    	if(!isset($nationalitys)) {
	    	RClassesImporter::cls("dbo.finders.NationalityFinder" );
	    	$finder = new NationalityFinder();
	    	
	    	$nationalityList = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$nationalitys = array();
	    	foreach ($nationalityList as $nationality) {
	    		$nationalitys[$nationality->nationality_id] = $nationality->nationality_name;
	    	}
    	}
    	return $nationalitys;
    }
    
    function createEthnicityList() {
    	static $nationalitys;
    	if(!isset($nationalitys)) {
	    	RClassesImporter::cls("dbo.finders.EthnicityFinder" );
	    	$finder = new EthnicityFinder();
	    	
	    	$nationalityList = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$nationalitys = array();
	    	foreach ($nationalityList as $nationality) {
	    		$nationalitys[$nationality->ethnicity_id] = $nationality->ethnicity_name;
	    	}
    	}
    	return $nationalitys;
    }
    
    function createLookingForList() {
    	static $lookingfors;
    	if(!isset($lookingfors)) {
	    	RClassesImporter::cls("dbo.finders.LookingForFinder" );
	    	$finder = new LookingForFinder();
	    	
	    	$lookingFors = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$lookingfors = array();
	    	foreach ($lookingFors as $looking) {
	    		$lookingfors[$looking->looking_id] = $looking->looking_name;
	    	}
    	}
    	return $lookingfors;
    }
    
    function createSexualList() {
    	static $sexuals;
    	if(!isset($sexuals)) {
	    	RClassesImporter::cls("dbo.finders.SexualOrientationFinder" );
	    	$finder = new SexualOrientationFinder();
	    	
	    	$sexualss = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$sexuals = array();
	    	foreach ($sexualss as $sexual) {
	    		$sexuals[$sexual->sexual_id] = $sexual->sexual_name;
	    	}
    	}
    	return $sexuals;
    }
    
    function createHeightList() {
    	static $heights;
    	if(!isset($heights)) {
	    	RClassesImporter::cls("dbo.finders.HeightFinder" );
	    	$finder = new HeightFinder();
	    	
	    	$heightss = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$heights = array();
	    	foreach ($heightss as $height) {
	    		$heights[$height->height_id] = $height->height_name;
	    	}
    	}
    	return $heights;
    }
    
    function createBodyTypeList() {
    	static $bodytypes;
    	if(!isset($bodytypes)) {
	    	RClassesImporter::cls("dbo.finders.BodyTypeFinder" );
	    	$finder = new BodyTypeFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$bodytypes = array();
	    	foreach ($bodys as $body) {
	    		$bodytypes[$body->body_id] = $body->body_name;
	    	}
    	}
    	return $bodytypes;
    }
    
    function createMaritalList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.MaritalStatusFinder" );
	    	$finder = new MaritalStatusFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->status_id] = $body->status_name;
	    	}
    	}
    	return $maritals;
    }
    
    function createCircumcisedList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.CircumcisedFinder" );
	    	$finder = new CircumcisedFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->circumcised_id] = $body->circumcised_name;
	    	}
    	}
    	return $maritals;
    }
    
    function createLanguagesList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.ProfilesLanguageFinder" );
	    	$finder = new ProfilesLanguageFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->language_id] = $body->language_name;
	    	}
    	}
    	return $maritals;
    }
    
    function createEthnicity() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.ProfilesEthnicityFinder" );
	    	$finder = new ProfilesEthnicityFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->ethnicity_id] = $body->ethnicity_name;
	    	}
    	}
    	return $maritals;
    }
    
	function createSexList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.ProfileSexFinder" );
	    	$finder = new ProfileSexFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->sex_id] = $body->sex_name;
	    	}
    	}
    	return $maritals;
    }
    
    
	function createSexChooseList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.SexForFinder" );
	    	$finder = new SexForFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->sex_for_id] = $body->sex_for_name;
	    	}
    	}
    	return $maritals;
    }
    
	function createSexualChooseList() {
    	static $maritals;
    	if(!isset($maritals)) {
	    	RClassesImporter::cls("dbo.finders.SexualPreferenceFinder" );
	    	$finder = new SexualPreferenceFinder();
	    	
	    	$bodys = SysDatabase::loadObjectList($finder->getSelectSQL());
	    	$maritals = array();
	    	foreach ($bodys as $body) {
	    		$maritals[$body->sexual_id] = $body->sexual_name;
	    	}
    	}
    	return $maritals;
    }
    
    /**
     * Create user profile for user_id
     * @param $user_id
     * @return unknown_type
     */
    function createProfiles($user_id, $full = false, $removeFriend = false) {
    	static $userArray;
    	$templatePath = SYS_CUR_TMPL_URL;
    	// Hardcode this function
    	if(!isset($userArray[$user_id])) {
    		// Hard code. Create query and use sysdatabase
    		$query = "SELECT m.user_name, m.member_pic, YEAR(NOW()) - YEAR(m.birthday) + 1 AS age, mp.avatar_url, CONCAT(mp.city, ', ', ct.country_name) AS location, mp.target_signup, ms.sex_name AS gender, mp.yahoo_id, mp.skype_id, mg.group_name, mg.group_id".
    				" FROM member As m".
    				" LEFT JOIN member_sex AS ms ON m.sex = ms.sex_id".
    				" LEFT JOIN member_profiles AS mp ON mp.member_id = m.member_id".
    				" LEFT JOIN country AS ct ON ct.country_id = mp.country".
    				" LEFT JOIN member_group AS mg ON mg.group_id = m.member".
    				" WHERE m.member_id = ".$user_id;
    		$memberObj = SysDatabase::loadObject($query);
    		$sendPrivateMessage = new SiteResource('users', 'compose');
    		$sendPrivateMessage->setExtend('receiver', $memberObj->user_name);
    		$sendPrivateMessage = $sendPrivateMessage->getLink();
    		$cloneResource = SysRequest::cloneResource();
    		$_SESSION['linkOld'] = $cloneResource->getLink();
    		if($removeFriend) {
	    		$addMyFriend = new SiteResource('friend', 'removefriend');
	    		$imgLink = "{$templatePath}images/remove_friend.png";
    		} else {
    			$addMyFriend = new SiteResource('friend', 'addtofriend');
	    		$imgLink = "{$templatePath}images/add_friend.png";
    		}
    		$addMyFriend->setExtend('user_id', $user_id);
    		
	    	$addMyFriend = $addMyFriend->getLink();
    		
    		if( !empty( $memberObj->member_pic ) ) {
    			RClassesImporter::cls("tshirt.classes.CAdultHelper");
    			$avatar	=	SYS_ROOT_URL.CAdultHelper::getBestThumb($memberObj->member_pic,90,90);
    			$avatar = '<img src="'.$avatar.'" title="'.$memberObj->user_name.'" alt="'.$memberObj->user_name.'" border="0" />';
    		}
    		$userPage = SYS_ROOT_URL.$memberObj->user_name;
    		$groupName = '<img src="'.SYS_CUR_TMPL_URL.'images/'.$memberObj->group_id.'.png" title="'.$memberObj->group_name.'" alt="'.$memberObj->group_name.'" border="0" />';
    		$memberObj->skype_id = HTMLHelper::createSkypeIcon($memberObj->skype_id, $full);
    		$memberObj->yahoo_id = HTMLHelper::createYahooIcon($memberObj->yahoo_id, $full);
    		eval('$userArray[$user_id] = "'.SysTemplate::loadTemplate ( "user_panel", SYS_ROOT_PATH).'";');
    	}
    	return $userArray[$user_id];
    }
    
    
    function createColorPicker($nameEle = 'colorPicker', $default='1A1A1A') {
    	// add javascript file
    	static $loaded;
    	
    	if(!isset($loaded)) {
    		$loaded = 0;
    		// add stylesheet and js for this feature
    		SysResponse::addStyleSheetFile(SYS_CUR_TMPL_URL.'js/colorpicker/css/colorpicker.css');
			SysResponse::addJavascriptFile(SYS_CUR_TMPL_URL.'js/colorpicker/js/colorpicker.js');
    	}
    	$loaded++;
    	SysResponse::addJavascriptContent("
    	$(document).ready(function() {
	    	$('#bgColorPicker{$loaded} div').css('backgroundColor', '#' + $('#colorpickerField{$loaded}').val());
			$('#bgColorPicker{$loaded}').ColorPicker({
				color: '#' + $('#colorpickerField{$loaded}').val(),
				onShow: function (colpkr) {
					$(colpkr).fadeIn(500);
					return false;
				},
				onHide: function (colpkr) {
					$(colpkr).fadeOut(500);
					return false;
				},
				onChange: function (hsb, hex, rgb) {
					$('#bgColorPicker{$loaded} div').css('backgroundColor', '#' + hex);
					$('#colorpickerField{$loaded}').val(hex);
				}
			});
		});");
    	return '<div class="colorPicker" id="bgColorPicker'.$loaded.'"><div>&nbsp;</div></div>
				<input type="hidden" value="'.$default.'" name="'.$nameEle.'" id="colorpickerField'.$loaded.'" size="6" maxlength="6"/>';
    }
    
    
    function createMessageWarning($msg = '') {
    	if(empty($msg)) {
    		$msg = 'Your current group cannot access this feature. Please upgrade your membership to continue';
    	}
    	$msg = '<a href="http://www.paypal.com" target="_blank"><img src="'.SYS_CUR_TMPL_URL.'images/paypal_logo.gif" title="Paid with paypal" alt="paid with paypal" border="0"/></a><br />'.$msg;
    	$msg .= "\n<br />\n";
    	$upgrade = new SiteResource('users', 'membership');
    	$msg .= "<a href=\"{$upgrade->getLink()}\">Click here to upgrade your membership</a>";
    	return $msg;
    }
}